from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import time

d = webdriver.Chrome()

d.get('https://www.qq.com/')
yaowen = d.find_element(By.XPATH,'/html/body/div[1]/div[4]/div[1]/div[2]/div/div[2]/div/ul[1]/li[1]/a')
biaoti = yaowen.text
yaowen.click()
all_windows = d.window_handles
d.switch_to.window(all_windows[1])
e = d.find_element(By.CSS_SELECTOR,'[class="content-article"]')
neirong = e.text
d.switch_to.window(all_windows[0])
time.sleep(1)


d.get('http://192.168.0.125:9009/')
time.sleep(1)

js = "window.scrollTo(0,1000)"
d.execute_script(js)
time.sleep(1)
login = d.find_element(By.LINK_TEXT,'登录')
login.click()

name = d.find_element(By.CSS_SELECTOR,'[id="user_login"]')
name.send_keys('admin')
pwd = d.find_element(By.CSS_SELECTOR,'[name="pwd"]')
pwd.send_keys('admin123')
login_1 = d.find_element(By.CSS_SELECTOR,'[name="wp-submit"]')
login_1.click()
time.sleep(1)

wenzhang = d.find_element(By.CSS_SELECTOR,'[id="menu-posts"]')
ActionChains(d).move_to_element(wenzhang).perform()
write = d.find_element(By.LINK_TEXT,'写文章')
write.click()
time.sleep(1)


title = d.find_element(By.CSS_SELECTOR,'[name="post_title"]')
title.send_keys(biaoti)
f = d.find_element(By.CSS_SELECTOR,'[id="content_ifr"]')
d.switch_to.frame(f)
content = d.find_element(By.CSS_SELECTOR,'[id="tinymce"]')
content.send_keys(neirong)
d.switch_to.default_content()

js = "window.scrollTo(0,0)"
d.execute_script(js)
time.sleep(1)

pulish = d.find_element(By.CSS_SELECTOR,'[name="publish"]')
pulish.click()

time.sleep(5)
d.quit()



